package com.aidong.search.biz.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aidong.activity.entity.Member;
import com.aidong.search.biz.SearchBiz;
import com.aidong.search.dao.SearchDao;
import com.aidong.search.entity.NearbyPersonEntity;


/**
 * 查找附近的人service
 * @author user
 *
 */
@Service("searchBiz")
public class SearchBizImpl implements SearchBiz {
	
	private SearchDao searchDao;

	@Autowired
	public void setSearchDao(SearchDao searchDao) {
		this.searchDao = searchDao;
	}

	@Override
	public List<NearbyPersonEntity> searchNearbyPerson(Map<String, Object> map){

		int  defaultRange = 3000;
		
		double myLat=(double) map.get("lat");
		double myLon=(double) map.get("lon");
		
		Double latitude = myLat;    
        Double longitude = myLon;    
    
        Double degree = (24901 * 1609) / 360.0;    
        double raidusMile = defaultRange;    
    
        Double dpmLat = 1 / degree;    
        Double radiusLat = dpmLat * raidusMile;    
        Double minLat = latitude - radiusLat;    
        Double maxLat = latitude + radiusLat;    
    
        Double mpdLng = degree * Math.cos(latitude * (Math.PI / 180));    
        Double dpmLng = 1 / mpdLng;                 
        Double radiusLng = dpmLng * raidusMile;     
        Double minLng = longitude - radiusLng;      
        Double maxLng = longitude + radiusLng;   
		
//		int  defaultRange = 5;
//		double myLat=(double) map.get("lat");
//		double myLon=(double) map.get("lon");
//		double range = 180 / Math.PI * defaultRange / 6372.797;  
//		double lngR = range / Math.cos(myLon * Math.PI / 180.0);
//		double maxLat = myLat + range;
//		double minLat = myLat - range;
//		double maxLon = myLon + lngR;
//		double minLon = myLon - lngR;
		map.put("maxLat", maxLat);
		map.put("minLat", minLat);
		map.put("maxLon", maxLng);
		map.put("minLon", minLng);
		return searchDao.searchNearbyPerson(map);
	}

	@Override
	public List<Map<String, Object>> getNearbyPersonInfo(Map<String, Object> map) {
		return searchDao.getNearbyPersonInfo(map);
	}

	/**
	 * 是否已关注对方爱动号
	 * @param map
	 */
	@Override
	public int getIfAttention(Map<String, Object> map) {
		return searchDao.getIfAttention(map);
	}

	/**
	 * 月排行榜
	 * @return
	 */
	@Override
	public List<Member> getMonthRanking(Map<String, Object> map) {
		return searchDao.getMonthRanking(map);
	}

	/**
	 * 推荐的人
	 * @return
	 */
	@Override
	public List<Member> getRecommendRanking(Map<String, Object> map) {
		return searchDao.getRecommendRanking(map);
	}

}
